#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QTextLine>


#include <QDebug>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::finishedSlot(QNetworkReply *reply)
{
    if (reply->error() == QNetworkReply::NoError) {
        QByteArray bytes = reply->readAll();
        qDebug() << bytes;
        ui->textLine->setText(bytes);
//        if (reply->url() == QUrl("http://127.0.0.1/8081/qt")) {

//        }
    }
}

void Widget::on_pushButton_clicked()
{
    QNetworkAccessManager *accessManager = new QNetworkAccessManager(this);
    connect(accessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedSlot(QNetworkReply*)));

   QNetworkRequest request;
   request.setUrl(QUrl("http://127.0.0.1:8080/blogs/qt"));

   //get
   accessManager->get(request);

//   request.setUrl(QUrl("http://127.0.0.1:8088/post"));
//   QByteArray postData;
//   postData.append("b=qt");

//   //post
//   accessManager->post(request, postData);
}
